GtkDialog: Make headerbar buttons homogeneous
authorMatthias Clasen <mclasen@redhat.com>
Sat, 8 Feb 2014 03:36:24 +0000 (22:36 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 8 Feb 2014 03:36:24 +0000 (22:36 -0500)
The buttons in headerbars should be all the same width. Since
GtkHeaderBar doesn't have a homogeneous mode, use a size group
to achieve this.

https://bugzilla.gnome.org/show_bug.cgi?id=723672

gtk/gtkdialog.c

index a597ebe337bc6b7ad57fed5373f370bff30af5bc..6b0cc7536dfc37e177bce53ffc0277543761b3d4 100644 (file)
@@ -43,6 +43,7 @@
 #include "gtksettings.h"
 #include "gtktypebuiltins.h"
 #include "deprecated/gtkstock.h"
+#include "gtksizegroup.h"
 
 /**
  * SECTION:gtkdialog
@@ -169,6 +170,7 @@ struct _GtkDialogPrivate
   GtkWidget *vbox;
   GtkWidget *headerbar;
   GtkWidget *action_area;
+  GtkSizeGroup *size_group;
 
   gint use_header_bar;
   gboolean constructed;
@@ -377,6 +379,8 @@ add_to_header_bar (GtkDialog *dialog,
   else 
     gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->headerbar), child);
 
+  gtk_size_group_add_widget (priv->size_group, child);
+
   if (response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_CLOSE)
     gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->headerbar), FALSE);
 }
@@ -457,6 +461,16 @@ gtk_dialog_constructor (GType                  type,
   return object;
 }
 
+static void
+gtk_dialog_finalize (GObject *obj)
+{
+  GtkDialog *dialog = GTK_DIALOG (obj);
+
+  g_object_unref (dialog->priv->size_group);
+
+  G_OBJECT_CLASS (gtk_dialog_parent_class)->finalize (obj);
+}
+
 static void
 gtk_dialog_class_init (GtkDialogClass *class)
 {
@@ -470,6 +484,7 @@ gtk_dialog_class_init (GtkDialogClass *class)
   gobject_class->constructor  = gtk_dialog_constructor;
   gobject_class->set_property = gtk_dialog_set_property;
   gobject_class->get_property = gtk_dialog_get_property;
+  gobject_class->finalize = gtk_dialog_finalize;
 
   widget_class->map = gtk_dialog_map;
   widget_class->style_updated = gtk_dialog_style_updated;
@@ -628,6 +643,7 @@ gtk_dialog_init (GtkDialog *dialog)
   dialog->priv = gtk_dialog_get_instance_private (dialog);
 
   dialog->priv->use_header_bar = -1;
+  dialog->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
   gtk_widget_init_template (GTK_WIDGET (dialog));